class Solution {
public:
    int takeCharacters(string s, int k) {
        int hash1[3];
        for(char c:s) hash1[c-'a']++;
        for(int i=0;i<3;++i)
        {
            if(hash1[i]<k) return -1;
            hash1[i]=hash1[i]-k;
        }
        int hash2[3];
        int w=0;
        for(int left=0,right=0;right<s.size();++right)
        {
            ++hash2[s[right]-'a'];
            while(left<=right&&hash2[s[right]-'a']>hash1[s[right]-'a'])
                --hash2[s[left++]-'a'];
            w=max(w,right-left+1);
        }
        return s.size()-w;
    }
};